/**
 * Created by denh on 17/2/22.
 */

var token = '<?=$this->token?>';
var userStatus = '<?=$user_status?>';
var page = 1;
var sign_id = 0;
var first = false;

var app = new Vue({
    el: '#container',
    data: {
        list: [],
        specialList : {}
    },
    methods : {

    }
});


function getData() {
    common.serverUrl = '<?=BACK_INTERFACE_BASE_URL?>';
    common.net('IndexController_classIndexByLabe',token, page, sign_id, function(result){
        if(result.code != 0) {
            common.showMsgBox(result.msg);
        } else {
            console.log(result);
            //添加标签名
            for (i = 0; i < result.result.cardList.length; i++) {
                for (var k in app.specialList) {
                    if (result.result.cardList[i].labe == app.specialList[k].id) {
                        result.result.cardList[i].labal_name = app.specialList[k].name;
                    }
                }
            }

            if (first) {
                app.list = result.result.cardList;
            } else {
                app.list = app.list.concat(result.result.cardList);
            }

            console.log(result.result.cardList.length);
            if (result.result.cardList.length == 10) {
                page++;
                first = false;
            } else {
                page = -1
            }

            $('.loading').hide();
        }
    });
}

//标签点击引导层
(function(){
    var is_yd = common.getCookie('course_yd'); //是否显示过引导层
    if (is_yd) {
        $('.yindao').hide();
    } else {
        $('.yindao').show();
        common.setCookie('course_yd', true);
    }

    //关闭引导层
    $('.yindao .button').click(function(){
        $('.yindao').hide();
    });
})();

$(window).scroll(function(){
    if ($(document).height() - $(document).scrollTop() - document.body.clientHeight == 0) {
        if (page != -1) {
            console.log('page:'+page);
            getData();
            $('.loading').show();
        }
    }
});

//显示下拉分类
$('.header_logo').click(function(){
    $(".sign_list").toggle();
    $('.sign_list_bg').toggle();

    $('.sign_down').toggle();
    $('.sign_up').toggle();
});

//点击阴影层，阴影层消失
$('.sign_list_bg').click(function(){
    $(".sign_list").toggle();
    $(this).toggle();
});

//点击下拉分类条目
$(".sign_list div").live('click', function(){
    sign_id = $(this).attr('sign_id');
    name = $(this).children('span').text();
    page = 0;
    first = true;
    getData(true);

    $(".sign_list div").removeClass('c_1');
    $(this).addClass('c_1');

    $(".header_logo h1").text(name);
    $('.header_logo').click();
});

//微信自定义分享
(function(){
    wx.config({
        debug: false,
        appId: '<?php echo $this->signPackage["appId"];?>',
        timestamp: '<?php echo $this->signPackage["timestamp"];?>',
        nonceStr: '<?php echo $this->signPackage["nonceStr"];?>',
        signature: '<?php echo $this->signPackage["signature"];?>',
        jsApiList: [
            'onMenuShareAppMessage',
            'onMenuShareTimeline',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'onMenuShareQZone'
        ]
    });

    title = '爱贝儿医-爱课堂';
    desc = '爱贝儿医—专注于做儿科医生间学习工作交流平台。平台拥有数十位来自省级以上重点三甲医院的儿科专家、重点医院儿科学科带头人、国内儿科权威人士组成的豪华专家团队。';
    links = '';
    imgUrl = '<?= G_SITE_CDN ?>/business/img/logoRed2.png';
    weixinShare(title, desc, links, imgUrl);
})();


app.list = <?=$this->data["list"]?>;
app.specialList = <?=$this->data["specialList"]?>;